package com.ruoyi.quartz.clearnup;

import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;

/**
 * 应用关闭时， 确保 Quartz Scheduler 正确关闭
 */
@Component
public class QuartzShutdownHook implements DisposableBean {

    @Autowired
    private Scheduler scheduler;

    @Override
    public void destroy() throws SchedulerException {
        if (scheduler != null) {
            scheduler.shutdown(true); // true 表示等待所有任务完成
        }
    }
}
